﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Maticsoft.DAL
{
	/// <summary>
	/// 数据访问类:Inventory
	/// </summary>
	public partial class Inventory
	{
		public Inventory()
		{}
		#region  BasicMethod



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.Inventory model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Inventory(");
            strSql.Append("spvalues,spnames,buyvalue,dictionarycode,ptype,cInvCode,cInvAddCode,cInvName,cInvStd,cInvCCode,cVenCode,cInvM_Unit,cInvA_Unit,cReplaceItem,cPosition,bSale,bPurchase,bSelf,bComsume,bProducing,bService,bAccessary,iInvExchRate,iTaxRate,iInvWeight,iVolume,iInvRCost,iInvSPrice,iInvSCost,iInvLSCost,iInvNCost,iInvAdvance,iInvBatch,iSafeNum,iTopSum,iLowSum,iOverStock,cInvABC,bInvQuality,bInvBatch,bInvEntrust,bInvOverStock,dSDate,dEDate,bFree1,bFree2,cInvDefine1,cInvDefine2,cInvDefine3,I_id,bInvType,iInvMPCost,cQuality,iInvSaleCost,iInvSCost1,iInvSCost2,iInvSCost3,iInvSCost4,iInvSCost5,iInvWSPrice,cInvHelp,iInvNTaxCost)");
            strSql.Append(" values (");
            strSql.Append("@spvalues,@spnames,@buyvalue,@dictionarycode,@ptype,@cInvCode,@cInvAddCode,@cInvName,@cInvStd,@cInvCCode,@cVenCode,@cInvM_Unit,@cInvA_Unit,@cReplaceItem,@cPosition,@bSale,@bPurchase,@bSelf,@bComsume,@bProducing,@bService,@bAccessary,@iInvExchRate,@iTaxRate,@iInvWeight,@iVolume,@iInvRCost,@iInvSPrice,@iInvSCost,@iInvLSCost,@iInvNCost,@iInvAdvance,@iInvBatch,@iSafeNum,@iTopSum,@iLowSum,@iOverStock,@cInvABC,@bInvQuality,@bInvBatch,@bInvEntrust,@bInvOverStock,@dSDate,@dEDate,@bFree1,@bFree2,@cInvDefine1,@cInvDefine2,@cInvDefine3,@I_id,@bInvType,@iInvMPCost,@cQuality,@iInvSaleCost,@iInvSCost1,@iInvSCost2,@iInvSCost3,@iInvSCost4,@iInvSCost5,@iInvWSPrice,@cInvHelp,@iInvNTaxCost)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@spvalues", SqlDbType.VarChar,150),
					new SqlParameter("@spnames", SqlDbType.VarChar,150),
					new SqlParameter("@buyvalue", SqlDbType.VarChar,50),
					new SqlParameter("@dictionarycode", SqlDbType.VarChar,50),
					new SqlParameter("@ptype", SqlDbType.BigInt,8),
					new SqlParameter("@cInvCode", SqlDbType.VarChar,20),
					new SqlParameter("@cInvAddCode", SqlDbType.VarChar,25),
					new SqlParameter("@cInvName", SqlDbType.VarChar,60),
					new SqlParameter("@cInvStd", SqlDbType.VarChar,60),
					new SqlParameter("@cInvCCode", SqlDbType.VarChar,12),
					new SqlParameter("@cVenCode", SqlDbType.VarChar,12),
					new SqlParameter("@cInvM_Unit", SqlDbType.VarChar,8),
					new SqlParameter("@cInvA_Unit", SqlDbType.VarChar,8),
					new SqlParameter("@cReplaceItem", SqlDbType.VarChar,20),
					new SqlParameter("@cPosition", SqlDbType.VarChar,20),
					new SqlParameter("@bSale", SqlDbType.Bit,1),
					new SqlParameter("@bPurchase", SqlDbType.Bit,1),
					new SqlParameter("@bSelf", SqlDbType.Bit,1),
					new SqlParameter("@bComsume", SqlDbType.Bit,1),
					new SqlParameter("@bProducing", SqlDbType.Bit,1),
					new SqlParameter("@bService", SqlDbType.Bit,1),
					new SqlParameter("@bAccessary", SqlDbType.Bit,1),
					new SqlParameter("@iInvExchRate", SqlDbType.Float,8),
					new SqlParameter("@iTaxRate", SqlDbType.SmallInt,2),
					new SqlParameter("@iInvWeight", SqlDbType.Float,8),
					new SqlParameter("@iVolume", SqlDbType.Float,8),
					new SqlParameter("@iInvRCost", SqlDbType.Float,8),
					new SqlParameter("@iInvSPrice", SqlDbType.Float,8),
					new SqlParameter("@iInvSCost", SqlDbType.Float,8),
					new SqlParameter("@iInvLSCost", SqlDbType.Float,8),
					new SqlParameter("@iInvNCost", SqlDbType.Float,8),
					new SqlParameter("@iInvAdvance", SqlDbType.Float,8),
					new SqlParameter("@iInvBatch", SqlDbType.Float,8),
					new SqlParameter("@iSafeNum", SqlDbType.Float,8),
					new SqlParameter("@iTopSum", SqlDbType.Float,8),
					new SqlParameter("@iLowSum", SqlDbType.Float,8),
					new SqlParameter("@iOverStock", SqlDbType.Float,8),
					new SqlParameter("@cInvABC", SqlDbType.VarChar,1),
					new SqlParameter("@bInvQuality", SqlDbType.Bit,1),
					new SqlParameter("@bInvBatch", SqlDbType.Bit,1),
					new SqlParameter("@bInvEntrust", SqlDbType.Bit,1),
					new SqlParameter("@bInvOverStock", SqlDbType.Bit,1),
					new SqlParameter("@dSDate", SqlDbType.DateTime),
					new SqlParameter("@dEDate", SqlDbType.DateTime),
					new SqlParameter("@bFree1", SqlDbType.Bit,1),
					new SqlParameter("@bFree2", SqlDbType.Bit,1),
					new SqlParameter("@cInvDefine1", SqlDbType.VarChar,120),
					new SqlParameter("@cInvDefine2", SqlDbType.VarChar,120),
					new SqlParameter("@cInvDefine3", SqlDbType.VarChar,120),
					new SqlParameter("@I_id", SqlDbType.Int,4),
					new SqlParameter("@bInvType", SqlDbType.Bit,1),
					new SqlParameter("@iInvMPCost", SqlDbType.Float,8),
					new SqlParameter("@cQuality", SqlDbType.NVarChar,100),
					new SqlParameter("@iInvSaleCost", SqlDbType.Float,8),
					new SqlParameter("@iInvSCost1", SqlDbType.Float,8),
					new SqlParameter("@iInvSCost2", SqlDbType.Float,8),
					new SqlParameter("@iInvSCost3", SqlDbType.Float,8),
					new SqlParameter("@iInvSCost4", SqlDbType.Float,8),
					new SqlParameter("@iInvSCost5", SqlDbType.Float,8),
					new SqlParameter("@iInvWSPrice", SqlDbType.Float,8),
					new SqlParameter("@cInvHelp", SqlDbType.VarChar,90),
					new SqlParameter("@iInvNTaxCost", SqlDbType.Float,8)};
            parameters[0].Value = model.spvalues;
            parameters[1].Value = model.spnames;
            parameters[2].Value = model.buyvalue;
            parameters[3].Value = model.dictionarycode;
            parameters[4].Value = model.ptype;
            parameters[5].Value = model.cInvCode;
            parameters[6].Value = model.cInvAddCode;
            parameters[7].Value = model.cInvName;
            parameters[8].Value = model.cInvStd;
            parameters[9].Value = model.cInvCCode;
            parameters[10].Value = model.cVenCode;
            parameters[11].Value = model.cInvM_Unit;
            parameters[12].Value = model.cInvA_Unit;
            parameters[13].Value = model.cReplaceItem;
            parameters[14].Value = model.cPosition;
            parameters[15].Value = model.bSale;
            parameters[16].Value = model.bPurchase;
            parameters[17].Value = model.bSelf;
            parameters[18].Value = model.bComsume;
            parameters[19].Value = model.bProducing;
            parameters[20].Value = model.bService;
            parameters[21].Value = model.bAccessary;
            parameters[22].Value = model.iInvExchRate;
            parameters[23].Value = model.iTaxRate;
            parameters[24].Value = model.iInvWeight;
            parameters[25].Value = model.iVolume;
            parameters[26].Value = model.iInvRCost;
            parameters[27].Value = model.iInvSPrice;
            parameters[28].Value = model.iInvSCost;
            parameters[29].Value = model.iInvLSCost;
            parameters[30].Value = model.iInvNCost;
            parameters[31].Value = model.iInvAdvance;
            parameters[32].Value = model.iInvBatch;
            parameters[33].Value = model.iSafeNum;
            parameters[34].Value = model.iTopSum;
            parameters[35].Value = model.iLowSum;
            parameters[36].Value = model.iOverStock;
            parameters[37].Value = model.cInvABC;
            parameters[38].Value = model.bInvQuality;
            parameters[39].Value = model.bInvBatch;
            parameters[40].Value = model.bInvEntrust;
            parameters[41].Value = model.bInvOverStock;
            parameters[42].Value = model.dSDate;
            parameters[43].Value = model.dEDate;
            parameters[44].Value = model.bFree1;
            parameters[45].Value = model.bFree2;
            parameters[46].Value = model.cInvDefine1;
            parameters[47].Value = model.cInvDefine2;
            parameters[48].Value = model.cInvDefine3;
            parameters[49].Value = model.I_id;
            parameters[50].Value = model.bInvType;
            parameters[51].Value = model.iInvMPCost;
            parameters[52].Value = model.cQuality;
            parameters[53].Value = model.iInvSaleCost;
            parameters[54].Value = model.iInvSCost1;
            parameters[55].Value = model.iInvSCost2;
            parameters[56].Value = model.iInvSCost3;
            parameters[57].Value = model.iInvSCost4;
            parameters[58].Value = model.iInvSCost5;
            parameters[59].Value = model.iInvWSPrice;
            parameters[60].Value = model.cInvHelp;
            parameters[61].Value = model.iInvNTaxCost;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.Inventory model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Inventory set ");
            strSql.Append("spvalues=@spvalues,");
            strSql.Append("spnames=@spnames,");
            strSql.Append("buyvalue=@buyvalue,");
            strSql.Append("dictionarycode=@dictionarycode,");
            strSql.Append("ptype=@ptype,");
            strSql.Append("cInvCode=@cInvCode,");
            strSql.Append("cInvAddCode=@cInvAddCode,");
            strSql.Append("cInvName=@cInvName,");
            strSql.Append("cInvStd=@cInvStd,");
            strSql.Append("cInvCCode=@cInvCCode,");
            strSql.Append("cVenCode=@cVenCode,");
            strSql.Append("cInvM_Unit=@cInvM_Unit,");
            strSql.Append("cInvA_Unit=@cInvA_Unit,");
            strSql.Append("cReplaceItem=@cReplaceItem,");
            strSql.Append("cPosition=@cPosition,");
            strSql.Append("bSale=@bSale,");
            strSql.Append("bPurchase=@bPurchase,");
            strSql.Append("bSelf=@bSelf,");
            strSql.Append("bComsume=@bComsume,");
            strSql.Append("bProducing=@bProducing,");
            strSql.Append("bService=@bService,");
            strSql.Append("bAccessary=@bAccessary,");
            strSql.Append("iInvExchRate=@iInvExchRate,");
            strSql.Append("iTaxRate=@iTaxRate,");
            strSql.Append("iInvWeight=@iInvWeight,");
            strSql.Append("iVolume=@iVolume,");
            strSql.Append("iInvRCost=@iInvRCost,");
            strSql.Append("iInvSPrice=@iInvSPrice,");
            strSql.Append("iInvSCost=@iInvSCost,");
            strSql.Append("iInvLSCost=@iInvLSCost,");
            strSql.Append("iInvNCost=@iInvNCost,");
            strSql.Append("iInvAdvance=@iInvAdvance,");
            strSql.Append("iInvBatch=@iInvBatch,");
            strSql.Append("iSafeNum=@iSafeNum,");
            strSql.Append("iTopSum=@iTopSum,");
            strSql.Append("iLowSum=@iLowSum,");
            strSql.Append("iOverStock=@iOverStock,");
            strSql.Append("cInvABC=@cInvABC,");
            strSql.Append("bInvQuality=@bInvQuality,");
            strSql.Append("bInvBatch=@bInvBatch,");
            strSql.Append("bInvEntrust=@bInvEntrust,");
            strSql.Append("bInvOverStock=@bInvOverStock,");
            strSql.Append("dSDate=@dSDate,");
            strSql.Append("dEDate=@dEDate,");
            strSql.Append("bFree1=@bFree1,");
            strSql.Append("bFree2=@bFree2,");
            strSql.Append("cInvDefine1=@cInvDefine1,");
            strSql.Append("cInvDefine2=@cInvDefine2,");
            strSql.Append("cInvDefine3=@cInvDefine3,");
            strSql.Append("I_id=@I_id,");
            strSql.Append("bInvType=@bInvType,");
            strSql.Append("iInvMPCost=@iInvMPCost,");
            strSql.Append("cQuality=@cQuality,");
            strSql.Append("iInvSaleCost=@iInvSaleCost,");
            strSql.Append("iInvSCost1=@iInvSCost1,");
            strSql.Append("iInvSCost2=@iInvSCost2,");
            strSql.Append("iInvSCost3=@iInvSCost3,");
            strSql.Append("iInvSCost4=@iInvSCost4,");
            strSql.Append("iInvSCost5=@iInvSCost5,");
            strSql.Append("iInvWSPrice=@iInvWSPrice,");
            strSql.Append("cInvHelp=@cInvHelp,");
            strSql.Append("iInvNTaxCost=@iInvNTaxCost");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@spvalues", SqlDbType.VarChar,150),
					new SqlParameter("@spnames", SqlDbType.VarChar,150),
					new SqlParameter("@buyvalue", SqlDbType.VarChar,50),
					new SqlParameter("@dictionarycode", SqlDbType.VarChar,50),
					new SqlParameter("@ptype", SqlDbType.BigInt,8),
					new SqlParameter("@cInvCode", SqlDbType.VarChar,20),
					new SqlParameter("@cInvAddCode", SqlDbType.VarChar,25),
					new SqlParameter("@cInvName", SqlDbType.VarChar,60),
					new SqlParameter("@cInvStd", SqlDbType.VarChar,60),
					new SqlParameter("@cInvCCode", SqlDbType.VarChar,12),
					new SqlParameter("@cVenCode", SqlDbType.VarChar,12),
					new SqlParameter("@cInvM_Unit", SqlDbType.VarChar,8),
					new SqlParameter("@cInvA_Unit", SqlDbType.VarChar,8),
					new SqlParameter("@cReplaceItem", SqlDbType.VarChar,20),
					new SqlParameter("@cPosition", SqlDbType.VarChar,20),
					new SqlParameter("@bSale", SqlDbType.Bit,1),
					new SqlParameter("@bPurchase", SqlDbType.Bit,1),
					new SqlParameter("@bSelf", SqlDbType.Bit,1),
					new SqlParameter("@bComsume", SqlDbType.Bit,1),
					new SqlParameter("@bProducing", SqlDbType.Bit,1),
					new SqlParameter("@bService", SqlDbType.Bit,1),
					new SqlParameter("@bAccessary", SqlDbType.Bit,1),
					new SqlParameter("@iInvExchRate", SqlDbType.Float,8),
					new SqlParameter("@iTaxRate", SqlDbType.SmallInt,2),
					new SqlParameter("@iInvWeight", SqlDbType.Float,8),
					new SqlParameter("@iVolume", SqlDbType.Float,8),
					new SqlParameter("@iInvRCost", SqlDbType.Float,8),
					new SqlParameter("@iInvSPrice", SqlDbType.Float,8),
					new SqlParameter("@iInvSCost", SqlDbType.Float,8),
					new SqlParameter("@iInvLSCost", SqlDbType.Float,8),
					new SqlParameter("@iInvNCost", SqlDbType.Float,8),
					new SqlParameter("@iInvAdvance", SqlDbType.Float,8),
					new SqlParameter("@iInvBatch", SqlDbType.Float,8),
					new SqlParameter("@iSafeNum", SqlDbType.Float,8),
					new SqlParameter("@iTopSum", SqlDbType.Float,8),
					new SqlParameter("@iLowSum", SqlDbType.Float,8),
					new SqlParameter("@iOverStock", SqlDbType.Float,8),
					new SqlParameter("@cInvABC", SqlDbType.VarChar,1),
					new SqlParameter("@bInvQuality", SqlDbType.Bit,1),
					new SqlParameter("@bInvBatch", SqlDbType.Bit,1),
					new SqlParameter("@bInvEntrust", SqlDbType.Bit,1),
					new SqlParameter("@bInvOverStock", SqlDbType.Bit,1),
					new SqlParameter("@dSDate", SqlDbType.DateTime),
					new SqlParameter("@dEDate", SqlDbType.DateTime),
					new SqlParameter("@bFree1", SqlDbType.Bit,1),
					new SqlParameter("@bFree2", SqlDbType.Bit,1),
					new SqlParameter("@cInvDefine1", SqlDbType.VarChar,120),
					new SqlParameter("@cInvDefine2", SqlDbType.VarChar,120),
					new SqlParameter("@cInvDefine3", SqlDbType.VarChar,120),
					new SqlParameter("@I_id", SqlDbType.Int,4),
					new SqlParameter("@bInvType", SqlDbType.Bit,1),
					new SqlParameter("@iInvMPCost", SqlDbType.Float,8),
					new SqlParameter("@cQuality", SqlDbType.NVarChar,100),
					new SqlParameter("@iInvSaleCost", SqlDbType.Float,8),
					new SqlParameter("@iInvSCost1", SqlDbType.Float,8),
					new SqlParameter("@iInvSCost2", SqlDbType.Float,8),
					new SqlParameter("@iInvSCost3", SqlDbType.Float,8),
					new SqlParameter("@iInvSCost4", SqlDbType.Float,8),
					new SqlParameter("@iInvSCost5", SqlDbType.Float,8),
					new SqlParameter("@iInvWSPrice", SqlDbType.Float,8),
					new SqlParameter("@cInvHelp", SqlDbType.VarChar,90),
					new SqlParameter("@iInvNTaxCost", SqlDbType.Float,8),
					new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = model.spvalues;
            parameters[1].Value = model.spnames;
            parameters[2].Value = model.buyvalue;
            parameters[3].Value = model.dictionarycode;
            parameters[4].Value = model.ptype;
            parameters[5].Value = model.cInvCode;
            parameters[6].Value = model.cInvAddCode;
            parameters[7].Value = model.cInvName;
            parameters[8].Value = model.cInvStd;
            parameters[9].Value = model.cInvCCode;
            parameters[10].Value = model.cVenCode;
            parameters[11].Value = model.cInvM_Unit;
            parameters[12].Value = model.cInvA_Unit;
            parameters[13].Value = model.cReplaceItem;
            parameters[14].Value = model.cPosition;
            parameters[15].Value = model.bSale;
            parameters[16].Value = model.bPurchase;
            parameters[17].Value = model.bSelf;
            parameters[18].Value = model.bComsume;
            parameters[19].Value = model.bProducing;
            parameters[20].Value = model.bService;
            parameters[21].Value = model.bAccessary;
            parameters[22].Value = model.iInvExchRate;
            parameters[23].Value = model.iTaxRate;
            parameters[24].Value = model.iInvWeight;
            parameters[25].Value = model.iVolume;
            parameters[26].Value = model.iInvRCost;
            parameters[27].Value = model.iInvSPrice;
            parameters[28].Value = model.iInvSCost;
            parameters[29].Value = model.iInvLSCost;
            parameters[30].Value = model.iInvNCost;
            parameters[31].Value = model.iInvAdvance;
            parameters[32].Value = model.iInvBatch;
            parameters[33].Value = model.iSafeNum;
            parameters[34].Value = model.iTopSum;
            parameters[35].Value = model.iLowSum;
            parameters[36].Value = model.iOverStock;
            parameters[37].Value = model.cInvABC;
            parameters[38].Value = model.bInvQuality;
            parameters[39].Value = model.bInvBatch;
            parameters[40].Value = model.bInvEntrust;
            parameters[41].Value = model.bInvOverStock;
            parameters[42].Value = model.dSDate;
            parameters[43].Value = model.dEDate;
            parameters[44].Value = model.bFree1;
            parameters[45].Value = model.bFree2;
            parameters[46].Value = model.cInvDefine1;
            parameters[47].Value = model.cInvDefine2;
            parameters[48].Value = model.cInvDefine3;
            parameters[49].Value = model.I_id;
            parameters[50].Value = model.bInvType;
            parameters[51].Value = model.iInvMPCost;
            parameters[52].Value = model.cQuality;
            parameters[53].Value = model.iInvSaleCost;
            parameters[54].Value = model.iInvSCost1;
            parameters[55].Value = model.iInvSCost2;
            parameters[56].Value = model.iInvSCost3;
            parameters[57].Value = model.iInvSCost4;
            parameters[58].Value = model.iInvSCost5;
            parameters[59].Value = model.iInvWSPrice;
            parameters[60].Value = model.cInvHelp;
            parameters[61].Value = model.iInvNTaxCost;
            parameters[62].Value = model.id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Inventory ");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
			parameters[0].Value = id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Inventory ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.Inventory GetModel(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,spvalues,spnames,buyvalue,dictionarycode,ptype,cInvCode,cInvAddCode,cInvName,cInvStd,cInvCCode,cVenCode,cInvM_Unit,cInvA_Unit,cReplaceItem,cPosition,bSale,bPurchase,bSelf,bComsume,bProducing,bService,bAccessary,iInvExchRate,iTaxRate,iInvWeight,iVolume,iInvRCost,iInvSPrice,iInvSCost,iInvLSCost,iInvNCost,iInvAdvance,iInvBatch,iSafeNum,iTopSum,iLowSum,iOverStock,cInvABC,bInvQuality,bInvBatch,bInvEntrust,bInvOverStock,dSDate,dEDate,bFree1,bFree2,cInvDefine1,cInvDefine2,cInvDefine3,I_id,bInvType,iInvMPCost,cQuality,iInvSaleCost,iInvSCost1,iInvSCost2,iInvSCost3,iInvSCost4,iInvSCost5,iInvWSPrice,cInvHelp,iInvNTaxCost from Inventory ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
            parameters[0].Value = id;

            Maticsoft.Model.Inventory model = new Maticsoft.Model.Inventory();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.Inventory DataRowToModel(DataRow row)
        {
            Maticsoft.Model.Inventory model = new Maticsoft.Model.Inventory();
            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["spvalues"] != null)
                {
                    model.spvalues = row["spvalues"].ToString();
                }
                if (row["spnames"] != null)
                {
                    model.spnames = row["spnames"].ToString();
                }
                if (row["buyvalue"] != null)
                {
                    model.buyvalue = row["buyvalue"].ToString();
                }
                if (row["dictionarycode"] != null)
                {
                    model.dictionarycode = row["dictionarycode"].ToString();
                }
                if (row["ptype"] != null && row["ptype"].ToString() != "")
                {
                    model.ptype = long.Parse(row["ptype"].ToString());
                }
                if (row["cInvCode"] != null)
                {
                    model.cInvCode = row["cInvCode"].ToString();
                }
                if (row["cInvAddCode"] != null)
                {
                    model.cInvAddCode = row["cInvAddCode"].ToString();
                }
                if (row["cInvName"] != null)
                {
                    model.cInvName = row["cInvName"].ToString();
                }
                if (row["cInvStd"] != null)
                {
                    model.cInvStd = row["cInvStd"].ToString();
                }
                if (row["cInvCCode"] != null)
                {
                    model.cInvCCode = row["cInvCCode"].ToString();
                }
                if (row["cVenCode"] != null)
                {
                    model.cVenCode = row["cVenCode"].ToString();
                }
                if (row["cInvM_Unit"] != null)
                {
                    model.cInvM_Unit = row["cInvM_Unit"].ToString();
                }
                if (row["cInvA_Unit"] != null)
                {
                    model.cInvA_Unit = row["cInvA_Unit"].ToString();
                }
                if (row["cReplaceItem"] != null)
                {
                    model.cReplaceItem = row["cReplaceItem"].ToString();
                }
                if (row["cPosition"] != null)
                {
                    model.cPosition = row["cPosition"].ToString();
                }
                if (row["bSale"] != null && row["bSale"].ToString() != "")
                {
                    if ((row["bSale"].ToString() == "1") || (row["bSale"].ToString().ToLower() == "true"))
                    {
                        model.bSale = true;
                    }
                    else
                    {
                        model.bSale = false;
                    }
                }
                if (row["bPurchase"] != null && row["bPurchase"].ToString() != "")
                {
                    if ((row["bPurchase"].ToString() == "1") || (row["bPurchase"].ToString().ToLower() == "true"))
                    {
                        model.bPurchase = true;
                    }
                    else
                    {
                        model.bPurchase = false;
                    }
                }
                if (row["bSelf"] != null && row["bSelf"].ToString() != "")
                {
                    if ((row["bSelf"].ToString() == "1") || (row["bSelf"].ToString().ToLower() == "true"))
                    {
                        model.bSelf = true;
                    }
                    else
                    {
                        model.bSelf = false;
                    }
                }
                if (row["bComsume"] != null && row["bComsume"].ToString() != "")
                {
                    if ((row["bComsume"].ToString() == "1") || (row["bComsume"].ToString().ToLower() == "true"))
                    {
                        model.bComsume = true;
                    }
                    else
                    {
                        model.bComsume = false;
                    }
                }
                if (row["bProducing"] != null && row["bProducing"].ToString() != "")
                {
                    if ((row["bProducing"].ToString() == "1") || (row["bProducing"].ToString().ToLower() == "true"))
                    {
                        model.bProducing = true;
                    }
                    else
                    {
                        model.bProducing = false;
                    }
                }
                if (row["bService"] != null && row["bService"].ToString() != "")
                {
                    if ((row["bService"].ToString() == "1") || (row["bService"].ToString().ToLower() == "true"))
                    {
                        model.bService = true;
                    }
                    else
                    {
                        model.bService = false;
                    }
                }
                if (row["bAccessary"] != null && row["bAccessary"].ToString() != "")
                {
                    if ((row["bAccessary"].ToString() == "1") || (row["bAccessary"].ToString().ToLower() == "true"))
                    {
                        model.bAccessary = true;
                    }
                    else
                    {
                        model.bAccessary = false;
                    }
                }
                if (row["iInvExchRate"] != null && row["iInvExchRate"].ToString() != "")
                {
                    model.iInvExchRate = decimal.Parse(row["iInvExchRate"].ToString());
                }
                if (row["iTaxRate"] != null && row["iTaxRate"].ToString() != "")
                {
                    model.iTaxRate = int.Parse(row["iTaxRate"].ToString());
                }
                if (row["iInvWeight"] != null && row["iInvWeight"].ToString() != "")
                {
                    model.iInvWeight = decimal.Parse(row["iInvWeight"].ToString());
                }
                if (row["iVolume"] != null && row["iVolume"].ToString() != "")
                {
                    model.iVolume = decimal.Parse(row["iVolume"].ToString());
                }
                if (row["iInvRCost"] != null && row["iInvRCost"].ToString() != "")
                {
                    model.iInvRCost = decimal.Parse(row["iInvRCost"].ToString());
                }
                if (row["iInvSPrice"] != null && row["iInvSPrice"].ToString() != "")
                {
                    model.iInvSPrice = decimal.Parse(row["iInvSPrice"].ToString());
                }
                if (row["iInvSCost"] != null && row["iInvSCost"].ToString() != "")
                {
                    model.iInvSCost = decimal.Parse(row["iInvSCost"].ToString());
                }
                if (row["iInvLSCost"] != null && row["iInvLSCost"].ToString() != "")
                {
                    model.iInvLSCost = decimal.Parse(row["iInvLSCost"].ToString());
                }
                if (row["iInvNCost"] != null && row["iInvNCost"].ToString() != "")
                {
                    model.iInvNCost = decimal.Parse(row["iInvNCost"].ToString());
                }
                if (row["iInvAdvance"] != null && row["iInvAdvance"].ToString() != "")
                {
                    model.iInvAdvance = decimal.Parse(row["iInvAdvance"].ToString());
                }
                if (row["iInvBatch"] != null && row["iInvBatch"].ToString() != "")
                {
                    model.iInvBatch = decimal.Parse(row["iInvBatch"].ToString());
                }
                if (row["iSafeNum"] != null && row["iSafeNum"].ToString() != "")
                {
                    model.iSafeNum = decimal.Parse(row["iSafeNum"].ToString());
                }
                if (row["iTopSum"] != null && row["iTopSum"].ToString() != "")
                {
                    model.iTopSum = decimal.Parse(row["iTopSum"].ToString());
                }
                if (row["iLowSum"] != null && row["iLowSum"].ToString() != "")
                {
                    model.iLowSum = decimal.Parse(row["iLowSum"].ToString());
                }
                if (row["iOverStock"] != null && row["iOverStock"].ToString() != "")
                {
                    model.iOverStock = decimal.Parse(row["iOverStock"].ToString());
                }
                if (row["cInvABC"] != null)
                {
                    model.cInvABC = row["cInvABC"].ToString();
                }
                if (row["bInvQuality"] != null && row["bInvQuality"].ToString() != "")
                {
                    if ((row["bInvQuality"].ToString() == "1") || (row["bInvQuality"].ToString().ToLower() == "true"))
                    {
                        model.bInvQuality = true;
                    }
                    else
                    {
                        model.bInvQuality = false;
                    }
                }
                if (row["bInvBatch"] != null && row["bInvBatch"].ToString() != "")
                {
                    if ((row["bInvBatch"].ToString() == "1") || (row["bInvBatch"].ToString().ToLower() == "true"))
                    {
                        model.bInvBatch = true;
                    }
                    else
                    {
                        model.bInvBatch = false;
                    }
                }
                if (row["bInvEntrust"] != null && row["bInvEntrust"].ToString() != "")
                {
                    if ((row["bInvEntrust"].ToString() == "1") || (row["bInvEntrust"].ToString().ToLower() == "true"))
                    {
                        model.bInvEntrust = true;
                    }
                    else
                    {
                        model.bInvEntrust = false;
                    }
                }
                if (row["bInvOverStock"] != null && row["bInvOverStock"].ToString() != "")
                {
                    if ((row["bInvOverStock"].ToString() == "1") || (row["bInvOverStock"].ToString().ToLower() == "true"))
                    {
                        model.bInvOverStock = true;
                    }
                    else
                    {
                        model.bInvOverStock = false;
                    }
                }
                if (row["dSDate"] != null && row["dSDate"].ToString() != "")
                {
                    model.dSDate = DateTime.Parse(row["dSDate"].ToString());
                }
                if (row["dEDate"] != null && row["dEDate"].ToString() != "")
                {
                    model.dEDate = DateTime.Parse(row["dEDate"].ToString());
                }
                if (row["bFree1"] != null && row["bFree1"].ToString() != "")
                {
                    if ((row["bFree1"].ToString() == "1") || (row["bFree1"].ToString().ToLower() == "true"))
                    {
                        model.bFree1 = true;
                    }
                    else
                    {
                        model.bFree1 = false;
                    }
                }
                if (row["bFree2"] != null && row["bFree2"].ToString() != "")
                {
                    if ((row["bFree2"].ToString() == "1") || (row["bFree2"].ToString().ToLower() == "true"))
                    {
                        model.bFree2 = true;
                    }
                    else
                    {
                        model.bFree2 = false;
                    }
                }
                if (row["cInvDefine1"] != null)
                {
                    model.cInvDefine1 = row["cInvDefine1"].ToString();
                }
                if (row["cInvDefine2"] != null)
                {
                    model.cInvDefine2 = row["cInvDefine2"].ToString();
                }
                if (row["cInvDefine3"] != null)
                {
                    model.cInvDefine3 = row["cInvDefine3"].ToString();
                }
                if (row["I_id"] != null && row["I_id"].ToString() != "")
                {
                    model.I_id = int.Parse(row["I_id"].ToString());
                }
                if (row["bInvType"] != null && row["bInvType"].ToString() != "")
                {
                    if ((row["bInvType"].ToString() == "1") || (row["bInvType"].ToString().ToLower() == "true"))
                    {
                        model.bInvType = true;
                    }
                    else
                    {
                        model.bInvType = false;
                    }
                }
                if (row["iInvMPCost"] != null && row["iInvMPCost"].ToString() != "")
                {
                    model.iInvMPCost = decimal.Parse(row["iInvMPCost"].ToString());
                }
                if (row["cQuality"] != null)
                {
                    model.cQuality = row["cQuality"].ToString();
                }
                if (row["iInvSaleCost"] != null && row["iInvSaleCost"].ToString() != "")
                {
                    model.iInvSaleCost = decimal.Parse(row["iInvSaleCost"].ToString());
                }
                if (row["iInvSCost1"] != null && row["iInvSCost1"].ToString() != "")
                {
                    model.iInvSCost1 = decimal.Parse(row["iInvSCost1"].ToString());
                }
                if (row["iInvSCost2"] != null && row["iInvSCost2"].ToString() != "")
                {
                    model.iInvSCost2 = decimal.Parse(row["iInvSCost2"].ToString());
                }
                if (row["iInvSCost3"] != null && row["iInvSCost3"].ToString() != "")
                {
                    model.iInvSCost3 = decimal.Parse(row["iInvSCost3"].ToString());
                }
                if (row["iInvSCost4"] != null && row["iInvSCost4"].ToString() != "")
                {
                    model.iInvSCost4 = decimal.Parse(row["iInvSCost4"].ToString());
                }
                if (row["iInvSCost5"] != null && row["iInvSCost5"].ToString() != "")
                {
                    model.iInvSCost5 = decimal.Parse(row["iInvSCost5"].ToString());
                }
                if (row["iInvWSPrice"] != null && row["iInvWSPrice"].ToString() != "")
                {
                    model.iInvWSPrice = decimal.Parse(row["iInvWSPrice"].ToString());
                }
                if (row["cInvHelp"] != null)
                {
                    model.cInvHelp = row["cInvHelp"].ToString();
                }
                if (row["iInvNTaxCost"] != null && row["iInvNTaxCost"].ToString() != "")
                {
                    model.iInvNTaxCost = decimal.Parse(row["iInvNTaxCost"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.Inventory DataRowToModelnoid(DataRow row)
        {
            Maticsoft.Model.Inventory model = new Maticsoft.Model.Inventory();
            if (row != null)
            {
                if (row["cInvCode"] != null)
                {
                    model.cInvCode = row["cInvCode"].ToString();
                }
                if (row["cInvAddCode"] != null)
                {
                    model.cInvAddCode = row["cInvAddCode"].ToString();
                }
                if (row["cInvName"] != null)
                {
                    model.cInvName = row["cInvName"].ToString();
                }
                if (row["cInvStd"] != null)
                {
                    model.cInvStd = row["cInvStd"].ToString();
                }
                if (row["cInvCCode"] != null)
                {
                    model.cInvCCode = row["cInvCCode"].ToString();
                }
                if (row["cVenCode"] != null)
                {
                    model.cVenCode = row["cVenCode"].ToString();
                }
                if (row["cInvM_Unit"] != null)
                {
                    model.cInvM_Unit = row["cInvM_Unit"].ToString();
                }
                if (row["cInvA_Unit"] != null)
                {
                    model.cInvA_Unit = row["cInvA_Unit"].ToString();
                }
                if (row["cReplaceItem"] != null)
                {
                    model.cReplaceItem = row["cReplaceItem"].ToString();
                }
                if (row["cPosition"] != null)
                {
                    model.cPosition = row["cPosition"].ToString();
                }
                if (row["bSale"] != null && row["bSale"].ToString() != "")
                {
                    if ((row["bSale"].ToString() == "1") || (row["bSale"].ToString().ToLower() == "true"))
                    {
                        model.bSale = true;
                    }
                    else
                    {
                        model.bSale = false;
                    }
                }
                if (row["bPurchase"] != null && row["bPurchase"].ToString() != "")
                {
                    if ((row["bPurchase"].ToString() == "1") || (row["bPurchase"].ToString().ToLower() == "true"))
                    {
                        model.bPurchase = true;
                    }
                    else
                    {
                        model.bPurchase = false;
                    }
                }
                if (row["bSelf"] != null && row["bSelf"].ToString() != "")
                {
                    if ((row["bSelf"].ToString() == "1") || (row["bSelf"].ToString().ToLower() == "true"))
                    {
                        model.bSelf = true;
                    }
                    else
                    {
                        model.bSelf = false;
                    }
                }
                if (row["bComsume"] != null && row["bComsume"].ToString() != "")
                {
                    if ((row["bComsume"].ToString() == "1") || (row["bComsume"].ToString().ToLower() == "true"))
                    {
                        model.bComsume = true;
                    }
                    else
                    {
                        model.bComsume = false;
                    }
                }
                if (row["bProducing"] != null && row["bProducing"].ToString() != "")
                {
                    if ((row["bProducing"].ToString() == "1") || (row["bProducing"].ToString().ToLower() == "true"))
                    {
                        model.bProducing = true;
                    }
                    else
                    {
                        model.bProducing = false;
                    }
                }
                if (row["bService"] != null && row["bService"].ToString() != "")
                {
                    if ((row["bService"].ToString() == "1") || (row["bService"].ToString().ToLower() == "true"))
                    {
                        model.bService = true;
                    }
                    else
                    {
                        model.bService = false;
                    }
                }
                if (row["bAccessary"] != null && row["bAccessary"].ToString() != "")
                {
                    if ((row["bAccessary"].ToString() == "1") || (row["bAccessary"].ToString().ToLower() == "true"))
                    {
                        model.bAccessary = true;
                    }
                    else
                    {
                        model.bAccessary = false;
                    }
                }
                if (row["iInvExchRate"] != null && row["iInvExchRate"].ToString() != "")
                {
                    model.iInvExchRate = decimal.Parse(row["iInvExchRate"].ToString());
                }
                if (row["iTaxRate"] != null && row["iTaxRate"].ToString() != "")
                {
                    model.iTaxRate = int.Parse(row["iTaxRate"].ToString());
                }
                if (row["iInvWeight"] != null && row["iInvWeight"].ToString() != "")
                {
                    model.iInvWeight = decimal.Parse(row["iInvWeight"].ToString());
                }
                if (row["iVolume"] != null && row["iVolume"].ToString() != "")
                {
                    model.iVolume = decimal.Parse(row["iVolume"].ToString());
                }
                if (row["iInvRCost"] != null && row["iInvRCost"].ToString() != "")
                {
                    model.iInvRCost = decimal.Parse(row["iInvRCost"].ToString());
                }
                if (row["iInvSPrice"] != null && row["iInvSPrice"].ToString() != "")
                {
                    model.iInvSPrice = decimal.Parse(row["iInvSPrice"].ToString());
                }
                if (row["iInvSCost"] != null && row["iInvSCost"].ToString() != "")
                {
                    model.iInvSCost = decimal.Parse(row["iInvSCost"].ToString());
                }
                if (row["iInvLSCost"] != null && row["iInvLSCost"].ToString() != "")
                {
                    model.iInvLSCost = decimal.Parse(row["iInvLSCost"].ToString());
                }
                if (row["iInvNCost"] != null && row["iInvNCost"].ToString() != "")
                {
                    model.iInvNCost = decimal.Parse(row["iInvNCost"].ToString());
                }
                if (row["iInvAdvance"] != null && row["iInvAdvance"].ToString() != "")
                {
                    model.iInvAdvance = decimal.Parse(row["iInvAdvance"].ToString());
                }
                if (row["iInvBatch"] != null && row["iInvBatch"].ToString() != "")
                {
                    model.iInvBatch = decimal.Parse(row["iInvBatch"].ToString());
                }
                if (row["iSafeNum"] != null && row["iSafeNum"].ToString() != "")
                {
                    model.iSafeNum = decimal.Parse(row["iSafeNum"].ToString());
                }
                if (row["iTopSum"] != null && row["iTopSum"].ToString() != "")
                {
                    model.iTopSum = decimal.Parse(row["iTopSum"].ToString());
                }
                if (row["iLowSum"] != null && row["iLowSum"].ToString() != "")
                {
                    model.iLowSum = decimal.Parse(row["iLowSum"].ToString());
                }
                if (row["iOverStock"] != null && row["iOverStock"].ToString() != "")
                {
                    model.iOverStock = decimal.Parse(row["iOverStock"].ToString());
                }
                if (row["cInvABC"] != null)
                {
                    model.cInvABC = row["cInvABC"].ToString();
                }
                if (row["bInvQuality"] != null && row["bInvQuality"].ToString() != "")
                {
                    if ((row["bInvQuality"].ToString() == "1") || (row["bInvQuality"].ToString().ToLower() == "true"))
                    {
                        model.bInvQuality = true;
                    }
                    else
                    {
                        model.bInvQuality = false;
                    }
                }
                if (row["bInvBatch"] != null && row["bInvBatch"].ToString() != "")
                {
                    if ((row["bInvBatch"].ToString() == "1") || (row["bInvBatch"].ToString().ToLower() == "true"))
                    {
                        model.bInvBatch = true;
                    }
                    else
                    {
                        model.bInvBatch = false;
                    }
                }
                if (row["bInvEntrust"] != null && row["bInvEntrust"].ToString() != "")
                {
                    if ((row["bInvEntrust"].ToString() == "1") || (row["bInvEntrust"].ToString().ToLower() == "true"))
                    {
                        model.bInvEntrust = true;
                    }
                    else
                    {
                        model.bInvEntrust = false;
                    }
                }
                if (row["bInvOverStock"] != null && row["bInvOverStock"].ToString() != "")
                {
                    if ((row["bInvOverStock"].ToString() == "1") || (row["bInvOverStock"].ToString().ToLower() == "true"))
                    {
                        model.bInvOverStock = true;
                    }
                    else
                    {
                        model.bInvOverStock = false;
                    }
                }
                if (row["dSDate"] != null && row["dSDate"].ToString() != "")
                {
                    model.dSDate = DateTime.Parse(row["dSDate"].ToString());
                }
                if (row["dEDate"] != null && row["dEDate"].ToString() != "")
                {
                    model.dEDate = DateTime.Parse(row["dEDate"].ToString());
                }
                if (row["bFree1"] != null && row["bFree1"].ToString() != "")
                {
                    if ((row["bFree1"].ToString() == "1") || (row["bFree1"].ToString().ToLower() == "true"))
                    {
                        model.bFree1 = true;
                    }
                    else
                    {
                        model.bFree1 = false;
                    }
                }
                if (row["bFree2"] != null && row["bFree2"].ToString() != "")
                {
                    if ((row["bFree2"].ToString() == "1") || (row["bFree2"].ToString().ToLower() == "true"))
                    {
                        model.bFree2 = true;
                    }
                    else
                    {
                        model.bFree2 = false;
                    }
                }
                if (row["cInvDefine1"] != null)
                {
                    model.cInvDefine1 = row["cInvDefine1"].ToString();
                }
                if (row["cInvDefine2"] != null)
                {
                    model.cInvDefine2 = row["cInvDefine2"].ToString();
                }
                if (row["cInvDefine3"] != null)
                {
                    model.cInvDefine3 = row["cInvDefine3"].ToString();
                }
                if (row["I_id"] != null && row["I_id"].ToString() != "")
                {
                    model.I_id = int.Parse(row["I_id"].ToString());
                }
                if (row["bInvType"] != null && row["bInvType"].ToString() != "")
                {
                    if ((row["bInvType"].ToString() == "1") || (row["bInvType"].ToString().ToLower() == "true"))
                    {
                        model.bInvType = true;
                    }
                    else
                    {
                        model.bInvType = false;
                    }
                }
                if (row["iInvMPCost"] != null && row["iInvMPCost"].ToString() != "")
                {
                    model.iInvMPCost = decimal.Parse(row["iInvMPCost"].ToString());
                }
                if (row["cQuality"] != null)
                {
                    model.cQuality = row["cQuality"].ToString();
                }
                if (row["iInvSaleCost"] != null && row["iInvSaleCost"].ToString() != "")
                {
                    model.iInvSaleCost = decimal.Parse(row["iInvSaleCost"].ToString());
                }
                if (row["iInvSCost1"] != null && row["iInvSCost1"].ToString() != "")
                {
                    model.iInvSCost1 = decimal.Parse(row["iInvSCost1"].ToString());
                }
                if (row["iInvSCost2"] != null && row["iInvSCost2"].ToString() != "")
                {
                    model.iInvSCost2 = decimal.Parse(row["iInvSCost2"].ToString());
                }
                if (row["iInvSCost3"] != null && row["iInvSCost3"].ToString() != "")
                {
                    model.iInvSCost3 = decimal.Parse(row["iInvSCost3"].ToString());
                }
                if (row["iInvSCost4"] != null && row["iInvSCost4"].ToString() != "")
                {
                    model.iInvSCost4 = decimal.Parse(row["iInvSCost4"].ToString());
                }
                if (row["iInvSCost5"] != null && row["iInvSCost5"].ToString() != "")
                {
                    model.iInvSCost5 = decimal.Parse(row["iInvSCost5"].ToString());
                }
                if (row["iInvWSPrice"] != null && row["iInvWSPrice"].ToString() != "")
                {
                    model.iInvWSPrice = decimal.Parse(row["iInvWSPrice"].ToString());
                }
                if (row["cInvHelp"] != null)
                {
                    model.cInvHelp = row["cInvHelp"].ToString();
                }
                if (row["iInvNTaxCost"] != null && row["iInvNTaxCost"].ToString() != "")
                {
                    model.iInvNTaxCost = decimal.Parse(row["iInvNTaxCost"].ToString());
                }
            }
            return model;
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,spvalues,spnames,buyvalue,dictionarycode,ptype,cInvCode,cInvAddCode,cInvName,cInvStd,cInvCCode,cVenCode,cInvM_Unit,cInvA_Unit,cReplaceItem,cPosition,bSale,bPurchase,bSelf,bComsume,bProducing,bService,bAccessary,iInvExchRate,iTaxRate,iInvWeight,iVolume,iInvRCost,iInvSPrice,iInvSCost,iInvLSCost,iInvNCost,iInvAdvance,iInvBatch,iSafeNum,iTopSum,iLowSum,iOverStock,cInvABC,bInvQuality,bInvBatch,bInvEntrust,bInvOverStock,dSDate,dEDate,bFree1,bFree2,cInvDefine1,cInvDefine2,cInvDefine3,I_id,bInvType,iInvMPCost,cQuality,iInvSaleCost,iInvSCost1,iInvSCost2,iInvSCost3,iInvSCost4,iInvSCost5,iInvWSPrice,cInvHelp,iInvNTaxCost ");
            strSql.Append(" FROM Inventory ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
            strSql.Append(" id,spvalues,buyvalue,spnames,dictionarycode,ptype,cInvCode,cInvAddCode,cInvName,cInvStd,cInvCCode,cVenCode,cInvM_Unit,cInvA_Unit,cReplaceItem,cPosition,bSale,bPurchase,bSelf,bComsume,bProducing,bService,bAccessary,iInvExchRate,iTaxRate,iInvWeight,iVolume,iInvRCost,iInvSPrice,iInvSCost,iInvLSCost,iInvNCost,iInvAdvance,iInvBatch,iSafeNum,iTopSum,iLowSum,iOverStock,cInvABC,bInvQuality,bInvBatch,bInvEntrust,bInvOverStock,dSDate,dEDate,bFree1,bFree2,cInvDefine1,cInvDefine2,cInvDefine3,I_id,bInvType,iInvMPCost,cQuality,iInvSaleCost,iInvSCost1,iInvSCost2,iInvSCost3,iInvSCost4,iInvSCost5,iInvWSPrice,cInvHelp,iInvNTaxCost ");
			strSql.Append(" FROM Inventory ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM Inventory ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from Inventory T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "Inventory";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod
        /// <summary>
        /// 获取指定数据库物料分类
        /// </summary>
        public DataSet GetInventoryClassList(string id, string type, string ccodes)
        {
            DbHelperSQLP db = new DbHelperSQLP(SqlHelper.UFSystemSQLConnString);
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from UA_Account where cAcc_Id='" + id + "'");
            DataSet ds = db.Query(strSql.ToString());//获取指定套帐
            //获取指定数据库物料分类
            if (ds.Tables[0].Rows != null && ds.Tables[0].Rows.Count > 0)
            {
                DbHelperSQLP db2 = new DbHelperSQLP(string.Format("UFData_{0}_{1}", ds.Tables[0].Rows[0]["cAcc_Id"], ds.Tables[0].Rows[0]["iYear"]));
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append(string.Format("select * from Inventory where {0}=1", type));
                if (!string.IsNullOrEmpty(ccodes))
                {
                    strSql2.Append(" and (");
                    int i = 0;
                    foreach (string item in ccodes.Split(','))
                    {
                        if (i == 0)
                            strSql2.Append(" cInvCCode like '" + item + "%'");
                        else
                            strSql2.Append(" or cInvCCode like '" + item + "%'");
                        i++;
                    }
                    strSql2.Append(" )");
                }
                return db2.Query(strSql2.ToString());//获取指定数据源数据
            }
            else
            {
                return null;
            }
        }
        public DataSet GetProductInventoryClassList(string id, string type, string classype)
        {
            DbHelperSQLP db = new DbHelperSQLP(SqlHelper.UFSystemSQLConnString);
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from UA_Account where cAcc_Id='" + id + "'");
            DataSet ds = db.Query(strSql.ToString());//获取指定套帐
            //获取指定数据库物料分类
            if (ds.Tables[0].Rows != null && ds.Tables[0].Rows.Count > 0)
            {
                DbHelperSQLP db2 = new DbHelperSQLP(string.Format("UFData_{0}_{1}", ds.Tables[0].Rows[0]["cAcc_Id"], ds.Tables[0].Rows[0]["iYear"]));
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append(string.Format("select * from Inventory where {0}=1 and cInvCCode like '{1}%'", type, classype));
                return db2.Query(strSql2.ToString());//获取指定数据源数据
            }
            else
            {
                return null;
            }
        }
		#endregion  ExtensionMethod
	}
}

